<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gmtCreate">
              <a-input-number v-model="model.gmtCreate" placeholder="请输入创建时间" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="活动名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入活动名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="活动标签" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="activitytag">
              <a-input v-model="model.activitytag" placeholder="请输入活动标签"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="封面图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="coverImg">
              <a-input v-model="model.coverImg" placeholder="请输入封面图片"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="原始名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rawName">
              <a-input v-model="model.rawName" placeholder="请输入原始名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="模板" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="template">
              <a-input v-model="model.template" placeholder="请输入模板"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="模板原始名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="templateRawName">
              <a-input v-model="model.templateRawName" placeholder="请输入模板原始名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="模板头像" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="templateAvatar">
              <a-input v-model="model.templateAvatar" placeholder="请输入模板头像"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="模板平台" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="templatePlatform">
              <a-input v-model="model.templatePlatform" placeholder="请输入模板平台"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="模板目标" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="templateTarget">
              <a-input v-model="model.templateTarget" placeholder="请输入模板目标"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="模板退款次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="templateRefundNum">
              <a-input-number v-model="model.templateRefundNum" placeholder="请输入模板退款次数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="参与人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="joinCnt">
              <a-input-number v-model="model.joinCnt" placeholder="请输入参与人数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户头像" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userAvatar">
              <a-textarea v-model="model.userAvatar" rows="4" placeholder="请输入用户头像" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="文章标签" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="articleTag">
              <a-input v-model="model.articleTag" placeholder="请输入文章标签"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gmtStart">
              <a-input-number v-model="model.gmtStart" placeholder="请输入开始时间" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="时间点0" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gmt0">
              <a-input-number v-model="model.gmt0" placeholder="请输入时间点0" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="时间点1" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gmt1">
              <a-input-number v-model="model.gmt1" placeholder="请输入时间点1" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gmtEnd">
              <a-input-number v-model="model.gmtEnd" placeholder="请输入结束时间" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="价格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="price">
              <a-input-number v-model="model.price" placeholder="请输入价格" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="菜单" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="menu">
              <a-input v-model="model.menu" placeholder="请输入菜单"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否退款" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isRefund">
              <a-input-number v-model="model.isRefund" placeholder="请输入是否退款" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'CrawlPracticalExercisesActivityForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           gmtCreate: [
              { required: true, message: '请输入创建时间!'},
           ],
           name: [
              { required: true, message: '请输入活动名称!'},
           ],
           activitytag: [
              { required: true, message: '请输入活动标签!'},
           ],
           coverImg: [
              { required: true, message: '请输入封面图片!'},
           ],
           rawName: [
              { required: true, message: '请输入原始名称!'},
           ],
           templateRawName: [
              { required: true, message: '请输入模板原始名称!'},
           ],
           templateAvatar: [
              { required: true, message: '请输入模板头像!'},
           ],
           templatePlatform: [
              { required: true, message: '请输入模板平台!'},
           ],
           templateTarget: [
              { required: true, message: '请输入模板目标!'},
           ],
           templateRefundNum: [
              { required: true, message: '请输入模板退款次数!'},
           ],
           joinCnt: [
              { required: true, message: '请输入参与人数!'},
           ],
           userAvatar: [
              { required: true, message: '请输入用户头像!'},
           ],
           articleTag: [
              { required: true, message: '请输入文章标签!'},
           ],
           gmtStart: [
              { required: true, message: '请输入开始时间!'},
           ],
           gmt0: [
              { required: true, message: '请输入时间点0!'},
           ],
           gmt1: [
              { required: true, message: '请输入时间点1!'},
           ],
           gmtEnd: [
              { required: true, message: '请输入结束时间!'},
           ],
           price: [
              { required: true, message: '请输入价格!'},
           ],
           menu: [
              { required: true, message: '请输入菜单!'},
           ],
           isRefund: [
              { required: true, message: '请输入是否退款!'},
           ],
        },
        url: {
          add: "/crawlpracticalexercisesactivity/crawlPracticalExercisesActivity/add",
          edit: "/crawlpracticalexercisesactivity/crawlPracticalExercisesActivity/edit",
          queryById: "/crawlpracticalexercisesactivity/crawlPracticalExercisesActivity/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>